package com.hzhk.happyrent.utils;

import android.annotation.SuppressLint;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {
    public static String getFormatQuestionTime (long time) {
        long curTime = System.currentTimeMillis();
        long duration = (curTime - time) / 1000;
        if (duration < 60) {
            return "刚刚";
        } else if (duration / 60 < 60) {
            return duration / 60 + "分钟前";
        } else if (duration / 3600 < 24) {
            return duration / 3600 + "小时前";
        } else if (duration / 86400 < 30) {
            return duration / 86400 + "天前";
        } else {
            return duration / 2592000 + "月前";
        }
    }

    @SuppressLint("SimpleDateFormat")
    public static String getFormatEssenceTime (long time, String format) {
        Date date = new Date(time);
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    /**
     * 获取现在时间
     *
     * @return时间格式 yyyy-MM-dd
     */
    public static String getStringDateShort () {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(currentTime);
        return dateString;
    }
    public static String getStrTime(String timeStamp){
        String timeString = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long  l = Long.valueOf(timeStamp);
        timeString = sdf.format(new Date(l*1000l));//单位秒
        return timeString;
    }
    public static String getStrTimeYMD(String timeStamp){
        String timeString = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        long  l = Long.valueOf(timeStamp);
        timeString = sdf.format(new Date(l*1000l));//单位秒
        return timeString;
    }
}
